package player

import (
	"GameServer/Common/utils"
	"GameServer/Game/errors"
	"GameServer/Game/lib"
	"GameServer/Game/sp"
)

// 1018 公会签到积分
func (p *Player) UnionSignInRequest(req *sp.UnionSignInRequest) (res *sp.UnionSignInResponse) {
	us := p.User
	uProp, endTime, integral, surplus, err := lib.GetIntegral("UnionSignInRequest", us, p.Send)
	if err != nil {
		res = &sp.UnionSignInResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}

	p.TimelyUpdateProp(req.GetType(), uProp)
	utils.AsyncFunc(func() {
		p.UpdateProp(req.GetType(), uProp)
	})

	res = &sp.UnionSignInResponse{
		EndTime:  endTime,
		Integral: integral,
		Surplus:  surplus,
	}
	return
}

// 1020 公会签到积分信息
func (p *Player) UnionSignInInfoRequest(req *sp.UnionSignInInfoRequest) (res *sp.UnionSignInInfoResponse) {
	us := p.User
	// 公会签到积分信息
	endTime, integral, surplus, err := lib.HandleUnionSignIn(us)
	if err != nil {
		res = &sp.UnionSignInInfoResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}

	res = &sp.UnionSignInInfoResponse{
		EndTime:  endTime,
		Integral: integral,
		Surplus:  surplus,
	}
	return
}
